package com.starrk.myblog.foreground.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.starrk.myblog.foreground.entity.Authority;
import com.starrk.myblog.foreground.entity.Role;
import com.starrk.myblog.foreground.entity.RoleBlogger;
import com.starrk.myblog.foreground.entity.TbBlogger;
import com.starrk.myblog.foreground.mapper.TbBloggerDao;
import com.starrk.myblog.foreground.service.MPRoleBloggerService;
import com.starrk.myblog.foreground.service.MPTbBloggerService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Starrk
 * @since 2018-03-25
 */
@Service
@Transactional
public class TbBloggerServiceDiy extends ServiceImpl<TbBloggerDao, TbBlogger> implements MPTbBloggerService {
    public static final String BlOGGER_PREFIX = "TbBlogger";

    @Autowired
    TbBloggerDao tbBloggerDao;

    @Autowired
    RedisTemplate redisTemplate;



    @Override
    public TbBlogger selectById(Serializable id){
        TbBlogger tbBlogger = tbBloggerDao.selectById(id);
        String key = BlOGGER_PREFIX+id;
        String value = JSON.toJSONString(tbBlogger);
        redisTemplate.opsForValue().set(key,value);
        return tbBlogger;
    }

    @Override
    public List<Authority> findAuthorityByBloggerId(Long bloggerId) {
        return tbBloggerDao.findAuthorityByBloggerId(bloggerId);
    }

    @Override
    public List<Role> findRolesByBloggerId(Long  bloggerId) {
        return tbBloggerDao.findRolesByBloggerId(bloggerId);
    }

    @Override
    public List<Authority> findAuthorityByUsername(String username) {
        return tbBloggerDao.findAuthorityByUsername(username);
    }

    @Override
    public List<Role> findRolesByUsername(String username) {
        return tbBloggerDao.findRolesByUsername(username);
    }
}
